import CONST from "../const/global"

function login(userId,userName,token) {
    window.sessionStorage.setItem("userId", userId)
    window.sessionStorage.setItem("userName", userName)
    window.sessionStorage.setItem("token", token)
}

function getToken() {
    return window.sessionStorage.getItem("token");
}

function logout() {
    window.sessionStorage.removeItem("userId")
    window.sessionStorage.removeItem("userName")
    window.sessionStorage.removeItem("token")
}


function saveAuthList(authList){
    window.sessionStorage.setItem(CONST.AUTH_LIST_KEY,JSON.stringify(authList))
}

function getAuthList(){
    let item = window.sessionStorage.getItem(CONST.AUTH_LIST_KEY);
    if (item) {
        return JSON.parse(item)
    }
    return null
}

export default {
    login,
    logout,
    saveAuthList,
    getAuthList,
    getToken
}